﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="LedgerMonthlySummary.aspx.cs"
    Inherits="Main_Reports_Accounts_LedgerMonthlySummary" %>

<%@ Register Src="~/User Controls/PageHeading.ascx" TagName="heading" TagPrefix="acc" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Monthly Ledger Summary</title>
    <link href="../../../Styles/accounts.css" rel="stylesheet" type="text/css" />

    <script type="text/javascript">
        function printPartOfPage() {
            var printContent = '<html><head><link href="../../../Styles/accounts.css" rel="stylesheet" type="text/css" /></head><body>';
            var printDiv = document.getElementById("divPrint");           
            var lblCompanyName = document.getElementById("lblCompanyName").innerHTML;
            var lblHeading = document.getElementById("lblHeading").innerHTML;
            var grdDisplay = document.getElementById("grdDisplay");
            var inputRow = grdDisplay.getElementsByTagName("tr");
            var totalRow = inputRow.length;
            var firstPageRow = 35;
            var lastPageRow = 40;            
            var contentRow = totalRow - 3;
            for (var i = 0; i < contentRow; i++) {
                if (i <= firstPageRow) {
                    if (i == 0) {
                        printContent += '<div style="width: 90%; margin-top: 10px; margin-left: 5%; margin-right: 5%;">';
                        printContent += '<div style="width: 100%; text-align: center;">';
                        printContent += lblCompanyName + '</br></br>' + lblHeading + '</div>';
                        printContent += '<table class="gridview" cellspacing="0" rules="all" border="1" style="width:100%;border-collapse:collapse;">';
                        printContent += '<tr>' + inputRow[0].innerHTML + '</tr>';
                    }
                    else if (i == firstPageRow && i < contentRow) {
                        printContent += '<tr>' + inputRow[i].innerHTML + '</tr></table>';
                    }
                    else if (i == firstPageRow && i + 1 == contentRow) {
                        printContent += '<tr>' + inputRow[i].innerHTML + '</tr>';
                    }                    
                    else {
                        printContent += '<tr>' + inputRow[i].innerHTML + '</tr>';
                    }
                }
                else if (i > firstPageRow) {
                var intValue = parseInt(parseInt(i - firstPageRow) / lastPageRow);
                var floatValue = parseFloat(parseFloat(i - firstPageRow) / lastPageRow);
                var modValue = i % lastPageRow;                    
                    if (i - 1 == firstPageRow) {
                        printContent += '<div style="width: 100%; text-align: center;"><p style="page-break-before: always">' + lblHeading + '</p></div>';
                        printContent += '<table class="gridview" cellspacing="0" rules="all" border="1" style="width:100%;border-collapse:collapse;">';
                        printContent += '<tr>' + inputRow[0].innerHTML + '</tr>';
                        printContent += '<tr>' + inputRow[i].innerHTML + '</tr>';
                    }
                    else if (intValue == floatValue) {
                        printContent += '</table><div style="width: 100%; text-align: center;"><p style="page-break-before: always">' + lblHeading + '</p></div>';
                        printContent += '<table class="gridview" cellspacing="0" rules="all" border="1" style="width:100%;border-collapse:collapse;">';
                        printContent += '<tr>' + inputRow[0].innerHTML + '</tr>';
                        printContent += '<tr>' + inputRow[i].innerHTML + '</tr>';
                    }
                    else if ((modValue == 0) && (i < contentRow)) {
                        printContent += '<tr>' + inputRow[i].innerHTML + '</tr></table>';

                    }
                    else if ((modValue == 0) && (i + 1 == contentRow)) {
                        printContent += '<tr>' + inputRow[i].innerHTML + '</tr>';
                    }
                    else {
                        printContent += '<tr>' + inputRow[i].innerHTML + '</tr>';
                    }
                }
            }
            for (var i = contentRow; i < totalRow; i++) {
                printContent += '<tr>' + inputRow[i].innerHTML + '</tr>'
            }
            printContent += '</table></div></body></html>';
            var windowUrl = 'about:blank';
            var uniqueName = new Date();
            var windowName = 'Print' + uniqueName.getTime();            
            var printWindow = window.open(windowUrl, windowName, 'left=5000,top=5000,width=0,height=0');
            printWindow.document.write(printContent);
            printWindow.document.close();
            printWindow.focus();
            printWindow.print();
            printWindow.close();
            return false;
        }
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div style="width: 90%; margin-top: 10px; margin-left: 5%; margin-right: 5%;">
        <asp:HyperLink ID="hyperPrint" runat="server" onclick="return printPartOfPage();"
            NavigateUrl="#">Print</asp:HyperLink>
        <asp:HiddenField ID="hidLedgerName" runat="server" />
        <asp:HiddenField ID="hidLedgerId" runat="server" />
        <asp:HiddenField ID="hidFromDate" runat="server" />
        <asp:HiddenField ID="hidToDate" runat="server" />
    </div>
    <div id="divPrint" runat="server" style="width: 90%; margin-top: 10px; margin-left: 5%;
        margin-right: 5%;">
        <div style="width: 100%; text-align: center;">            
            <asp:Label ID="lblCompanyName" runat="server" Font-Bold="true" Font-Size="14px"></asp:Label><br /><br />
            <asp:Label ID="lblHeading" runat="server" Font-Size="11px"></asp:Label>
        </div>
        <div style="width: 100%; margin-top: 10px;">
           
        <asp:GridView ID="grdDisplay" DataKeyNames="TransactionID" AutoGenerateColumns="false"
                            CssClass="gridview" Width="100%" OnRowDataBound="grdDisplay_RowDataBound" ShowFooter="true"
                            runat="server">
                            <Columns>
                                <asp:BoundField DataField="TransactionDate" HeaderText="Date" DataFormatString="{0:dd-MMM-yyyy}" />
                                <asp:BoundField DataField="Particulars" HeaderText="Particulars" />
                                <asp:BoundField DataField="Name" HeaderText="Tran Type" />
                                <asp:BoundField DataField="TransactionNumber" HeaderText="Tran. No." />
                                <asp:TemplateField HeaderText="Debit" ItemStyle-HorizontalAlign="Right">
                                    <ItemTemplate>
                                        <asp:Label ID="lblDebit" runat="server" Text='<%# Eval("Debit")%>'></asp:Label>
                                        <asp:HiddenField ID="hidDebit" runat="server" Value='<%# Eval("Debit")%>' />
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Credit" ItemStyle-HorizontalAlign="Right">
                                    <ItemTemplate>
                                        <asp:Label ID="lblCredit" runat="server" Text='<%# Eval("Credit")%>'></asp:Label>
                                        <asp:HiddenField ID="hidCredit" runat="server" Value='<%# Eval("Credit")%>' />
                                    </ItemTemplate>
                                </asp:TemplateField>
                            </Columns>
                        </asp:GridView>
                  
        </div>
    </div>    
    </form>
</body>
</html>





